<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑商品</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="goodsId" id="goodsId" th:value="${goods.goodsId}">
                <input type="text" id="goodsName" class="layui-input"
                       lay-verify="required" name="goodsName" th:value="${goods.goodsName}">
            </div>
        </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="subtitle" class="layui-input"
                       lay-verify="subtitle" th:value="${goods.subtitle}">
            </div>
        </div>
    <div class="layui-form-item">
        <label class="layui-form-label">原价</label>
        <div class="layui-input-block">
            <input type="text" name="goodsEvaluate" class="layui-input"
                   lay-verify="goodsEvaluate" th:value="${goods.goodsEvaluate}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">现价</label>
        <div class="layui-input-block">
            <input type="text" name="goodsNowPrice" class="layui-input"
                   lay-verify="goodsNowPrice" th:value="${goods.goodsNowPrice}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" name="stock" class="layui-input"
                   lay-verify="stock" th:value="${goods.stock}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select type="text" name="goodsTypeId" class="layui-input"
                   lay-verify="required">
                <option th:each="type:${goodsTypes}" th:value="${type.goodsTypeId}" th:selected="${type.goodsTypeId eq goods.goodsTypeId}">[[${type.goodsTypeName}]]</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-block">
            <input type="text" name="goodsStart" id="goodsStart" class="layui-input"
                   lay-verify="goodsStart" th:value="${#dates.format(goods.goodsStart,'yyyy-MM-dd')}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-block">
            <input type="text" name="goodsEnd" id="goodsEnd" class="layui-input"
                   lay-verify="goodsEnd" th:value="${#dates.format(goods.goodsEnd,'yyyy-MM-dd')}">
        </div>
    </div><div class="layui-form-item">
    <label class="layui-form-label">点击数</label>
    <div class="layui-input-block">
        <input type="text" name="goodsClick" class="layui-input"
               lay-verify="goodsClick" th:value="${goods.goodsClick}">
    </div>
    </div><div class="layui-form-item">
        <label class="layui-form-label">拍品状态</label>
        <div class="layui-input-block">
            <input type="text" name="goodsState" class="layui-input"
                   lay-verify="goodsState" th:value="${goods.goodsState}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">拍品位置</label>
        <div class="layui-input-block">
            <input type="text" name="goodsPos" class="layui-input"
                   lay-verify="goodsPos" th:value="${goods.goodsPos}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">删除状态</label>
        <div class="layui-input-block">
            <select type="text" name="deleted" class="layui-input"
                   lay-verify="required">
                <option value="">直接选择或搜索选择</option>
                <option value="0" th:selected="${ '0' eq goods.deleted}">删除</option>
                <option value="1" th:selected="${ '1' eq goods.deleted}">正常</option>
            </select>
        </div>
    </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="updGood" lay-submit="" lay-filter="updUser">立即保存</button>
            </div>
        </div>
</form>



<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['form','laydate','layer','jquery'],function () {
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.jquery;
        laydate.render({
            elem:'#goodsStart',
            max:'new Date()',
            trigger:'click'
        })
        laydate.render({
            elem:'#goodsEnd',
            max:'new Date()',
            trigger:'click'
        })
        //修改

        form.on('submit(updUser)',function (data) {
            console.log(data);
            $.ajax({
                url:'/goods/updGood',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('修改成功',{icon:1},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })


    })
</script>
</body>
</html>